package com.jxwifi.cloud.quickclean.utils;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

public class CustomShadowViewMain extends ImageView {

    private String TAG = this.getClass().getSimpleName();
    private Paint mPaint;
    private DisplayMetrics dm;

    public CustomShadowViewMain(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPaint.setColor(Color.WHITE);
        dm = context.getResources().getDisplayMetrics();
        this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.i(TAG,"onDraw ==> width = "+getWidth()+" height = "+getHeight());
        //绘制阴影，param1：模糊半径；param2：x轴大小：param3：y轴大小；param4：阴影颜色
        mPaint.setShadowLayer( (float) 15,  (float) 18,  (float) 18, Color.LTGRAY);
        RectF rect = new RectF(0, 0, getWidth()-(int)(15.619047619 * dm.density), getHeight()-(int)(15.619047619 * dm.density));
        canvas.drawRoundRect(rect, (float) 15, (float) 15, mPaint);
    }
}
